package org.dromara.system.mq.config;

import org.dromara.system.config.GlobalConfig;
import org.springframework.amqp.core.*;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.util.HashMap;
import java.util.Map;

@Configuration
public class OrderQueueConfig {

    // 定义延时队列的交换机名称
    public static final String DELAYED_EXCHANGE_NAME = GlobalConfig.env + "order.delayed.exchange";

    //回调A端订单状态
    public static final String DELAYED_CALLA_QUEUE = GlobalConfig.env + "order.delayed.calla.queue";
    public static final String DELAYED_CALLA_KEY = GlobalConfig.env + "order.delayed.calla.key";

    //获取订单状态
    public static final String DELAYED_STATUS_QUEUE = GlobalConfig.env + "order.delayed.status.queue";
    public static final String DELAYED_STATUS_KEY = GlobalConfig.env + "order.delayed.get.status.key";

    //推送物流
    public static final String DELAYED_TRACK_QUEUE = GlobalConfig.env + "order.delayed.track.queue";
    public static final String DELAYED_TRACK_KEY = GlobalConfig.env + "order.delayed.track.key";

    //推送订单到审核站
    public static final String DELAYED_PUSH_QUEUE = GlobalConfig.env + "order.delayed.push.queue";
    public static final String DELAYED_PUSH_KEY = GlobalConfig.env + "order.delayed.push.key";

    //订单自动失败时间
    public static final String DELAYED_FAIL_QUEUE = GlobalConfig.env + "order.delayed.fail.queue";
    public static final String DELAYED_FAIL_KEY = GlobalConfig.env + "order.delayed.fail.key";


    // 创建延时队列的交换机
    @Bean
    public CustomExchange delayedExchange() {
        Map<String, Object> arguments = new HashMap<>();
        arguments.put("x-delayed-type", "direct");
        return new CustomExchange(DELAYED_EXCHANGE_NAME, "x-delayed-message", true, false, arguments);
    }

    /************************回调A端订单状态***********************************/
    // 创建延时队列的队列
    @Bean
    public Queue delayedCallAQueue() {
        return QueueBuilder.durable(DELAYED_CALLA_QUEUE).build();
    }

    // 将延时队列的队列绑定到交换机上
    @Bean
    public Binding delayedCallABinding() {
        return BindingBuilder.bind(delayedCallAQueue()).to(delayedExchange()).with(DELAYED_CALLA_KEY).noargs();
    }
    /************************回调A端订单状态***********************************/




    /************************向C端获取订单结果***********************************/
    @Bean
    public Queue delayedGetresultQueue() {
        return QueueBuilder.durable(DELAYED_STATUS_QUEUE).build();
    }

    @Bean
    public Binding delayedGetresultBinding() {
        return BindingBuilder.bind(delayedGetresultQueue()).to(delayedExchange()).with(DELAYED_STATUS_KEY).noargs();
    }
    /************************向C端获取订单结果***********************************/



    /************************推送物流延时队列***********************************/
    @Bean
    public Queue delayedTrackQueue() {
        return QueueBuilder.durable(DELAYED_TRACK_QUEUE).build();
    }

    @Bean
    public Binding delayedTrackBinding() {
        return BindingBuilder.bind(delayedTrackQueue()).to(delayedExchange()).with(DELAYED_TRACK_KEY).noargs();
    }
    /************************推送物流延时队列***********************************/



    /************************推送订单到审核站***********************************/
    @Bean
    public Queue delayedPushQueue() {
        return QueueBuilder.durable(DELAYED_PUSH_QUEUE).build();
    }

    @Bean
    public Binding delayedPushBinding() {
        return BindingBuilder.bind(delayedPushQueue()).to(delayedExchange()).with(DELAYED_PUSH_KEY).noargs();
    }
    /************************推送订单到审核站***********************************/



    /************************订单自动失败时间***********************************/
    @Bean
    public Queue delayedFailQueue() {
        return QueueBuilder.durable(DELAYED_FAIL_QUEUE).build();
    }

    @Bean
    public Binding delayedFailBinding() {
        return BindingBuilder.bind(delayedFailQueue()).to(delayedExchange()).with(DELAYED_FAIL_KEY).noargs();
    }
    /************************推送订单到审核站***********************************/
}
